using Admin2025.Domain.Entities.App;
using Admin2025.Domain.Repositories;
using Admin2025.Infrastructure.Data;
using Dapper;

namespace Admin2025.Infrastructure.Repositories;

public class PermissionRepository : Repository<AppPermission>, IPermissionRepository
{
    public PermissionRepository(Admin2025DbContext factory) : base(factory) { }

    public async Task<IEnumerable<AppPermission>> GetByRoleIdAsync(Guid roleId)
    {
        var sql = @"
            SELECT p.* FROM AppPermissions p
            INNER JOIN RolePermissions rp ON p.Id = rp.PermissionId
            WHERE rp.RoleId = @RoleId";
        return await _db.QueryAsync<AppPermission>(sql, new { RoleId = roleId });
    }
}